package com.jinchange.mysqlandredis.controller;

import com.jinchange.mysqlandredis.entity.Person;
import com.jinchange.mysqlandredis.service.PersonService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName: PersonController
 * @Author zhangjin
 * @Date 2021/8/6 14:47
 * @Description:    接口缓存案例
 * 访问 http://localhost:8080/person
 */
@RestController
public class PersonController {

    @Resource
    private PersonService personService;

    @GetMapping("/person")
    public Person getPerson(Long id) {
        return personService.findPerson(id);
    }

    @PutMapping("/person")
    public Person setPerson(Person person) {
        return personService.setPerson(person);
    }

    @DeleteMapping("person")
    public String deletePerson(Long id) {
        return personService.deletePerson(id) ? "删除成功" : "删除失败";
    }

    @PostMapping("/person")
    public Person addPerson(Person person) {
        return personService.addPerson(person);
    }
}
